#!/usr/bin/sh

set -euo pipefail

declare -A dockerfiles=(["Dockerfile"]="origin-meta.yaml" ["Dockerfile.dev"]="dev-meta.yaml")
# check dockerfile changes
for d in "${!dockerfiles[@]}"; do
  change=$(./hack/generate-dockerfile-from-midstream Dockerfile.in "${dockerfiles[$d]}"  | md5sum | cut -d ' ' -f1)
  if [ "$change" != "$(md5sum $d | cut -d ' ' -f1)" ] ; then
    echo "A change was found in CI file $d that was not sourced from the midstream file Dockerfile.in (or vice versa)."
    echo "Please reset the CI file (e.g. $d), update Dockerfile.in, run make gen-dockerfiles and commit the results"
    exit 1
  fi
done
